/**
 * @Auther: ChenforCode
 * @Date: 2018/9/12 00:23
 * @Description: 完成与登陆相关的业务逻辑
 */
package cn.chenforcode.service;

import cn.chenforcode.dao.BookAdminDAO;
import cn.chenforcode.dao.StuAdminDAO;
import cn.chenforcode.dao.StudentDAO;
import cn.chenforcode.entity.Book;
import cn.chenforcode.entity.BookAdmin;
import cn.chenforcode.entity.StuAdmin;
import cn.chenforcode.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginService {

    @Autowired
    private StudentDAO studentDAO;

    @Autowired
    private BookAdminDAO bookAdminDAO;

    @Autowired
    private StuAdminDAO stuAdminDAO;

    /**
     * @return java.lang.String
     * @Author ChenforCode
     * @Description //TODO 执行与登陆相关的业务逻辑
     * @Date 0:40 2018/9/12
     * @Param [uname, pwd]
     **/
    public String doLogin(String uname, String pwd) {
        //首先判断是不是最高权限管理员
        if ("admin".equals(uname) && "admin".equals(pwd)) {
            return "admin_success";
        } else {
            //判断是否为学生管理员
            StuAdmin stuAdmin = stuAdminDAO.getStuAdminBySaname(uname);
            if (stuAdmin != null && stuAdmin.getSapwd().equals(pwd)) {
                return "stuadmin_success";
            } else {
                //判断是否为图书管理员
                BookAdmin bookAdmin = bookAdminDAO.getBookAdminByBaname(uname);
                if (bookAdmin != null && bookAdmin.getBapwd().equals(pwd)) {
                    return "bookadmin_success";
                } else {
                    //判断是否为普通学生用户
                    Student stu = studentDAO.getStudentBySno(uname);
                    if (stu != null && stu.getSpwd().equals(pwd)) {
                        return "student_success";
                    } else {
                        return "failed";
                    }
                }
            }
        }
    }
}
